<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tab {
            margin: 100px auto 0;
            width: 600px;
        }

        .tab .options {
            border-top: 2px solid #06a86e;
            overflow: hidden;
        }

        .tab .options h3 {
            float: left;
            width: 150px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            font-size: 18px;
            font-weight: normal;
            color: #666;
            background-color: #f7f8f8;
            cursor: pointer;
        }
        .tab .contents{
            padding: 10px 0;
            height: 200px;
            overflow: hidden;
        }
        .tab .contents div {
            overflow: hidden;
            display: none;
            /* margin-bottom: 10px; */
        }
        .tab .contents div img{
            float: left;
            width: 150px;
            height: 200px;
        }
        .tab .options .active{
            background-color: #06a86e;
            color: #fff;
        }
        .tab .contents .show{
            display: block;
        }
    </style>
</head>
<body>
    <div class="tab">
        <div class="options">
            <h3 class="active">科幻</h3>
            <h3>爱情</h3>
            <h3>动作</h3>
            <h3>喜剧</h3>
        </div>
        <div class="contents">
            <div class="show">
                <img src="./imgs/e1.png" alt="">
                <img src="./imgs/e1.png" alt="">
                <img src="./imgs/e1.png" alt="">
                <img src="./imgs/e1.png" alt="">
            </div>
            <div>
                <img src="./imgs/e2.png" alt="">
                <img src="./imgs/e2.png" alt="">
                <img src="./imgs/e2.png" alt="">
                <img src="./imgs/e2.png" alt="">
            </div>
            <div>
                <img src="./imgs/e3.png" alt="">
                <img src="./imgs/e3.png" alt="">
                <img src="./imgs/e3.png" alt="">
                <img src="./imgs/e3.png" alt="">
            </div>
            <div>
                <img src="./imgs/e4.png" alt="">
                <img src="./imgs/e4.png" alt="">
                <img src="./imgs/e4.png" alt="">
                <img src="./imgs/e4.png" alt="">
            </div>
        </div>
    </div>
    <script>
        var h3s = document.querySelectorAll('.options h3');
        var divs = document.querySelectorAll('.contents div');

        for(var i = 0; i < h3s.length; i++){
            h3s[i].onclick = function (){
                for( var x = 0; x < h3s.length; x++){
                    if(h3s[x] === this){
                        h3s[x].className = 'active';
                        divs[x].className = 'show';
                    }else{
                        h3s[x].className = '';
                        divs[x].className = '';
                    }
                }
            }
        }
    </script>
</body>
</html>